﻿/**
* @projectName   图片操作辅助类
* @author        m晴朗
* @email         mengdadae@qq.com
* @blog          https://blog.csdn.net/qq_40666149
* 1.显示纯原始数据图像（RGB,yuv等）
* 2. rgb24分离r/g/b
* 3. yuvp420 分割 yuv
* 4. yuvp420转RGB24
* 5. rgb24转yuvp420
* 6. yuv420p转灰度
* 7. yuv420亮度减半
* 8. PSNR-质量评价
**/

#ifndef IMGHELPER_H
#define IMGHELPER_H
#include <QObject>
#include <QVector>
#include <QImage>
class imgHelper
{
public:

    //读取原始数据图片，比如纯rgb\yuv图片
    static QByteArray getImgFromFile(const QString &in_imgPath);

    ///rgb888分割r,g.b
    static QVector<QVector<unsigned char>> rgbSplit(const unsigned char *in_srcImg,int width, int height);
    static QVector<QImage> rgbSplit(const QImage &in_img);
    ///yuvp420 分割 yuv
    static QVector<QVector<unsigned char>> yuvSplit(const unsigned char *in_srcImg,int width, int height);

    //yuvp420转RGB888
    static QVector<unsigned char> yuv420pToRGB24(const unsigned char *in_srcImg,int width,int height);
    //rgb888转yuvp420
    static QVector<unsigned char> rgb24ToYUV420p(const unsigned char *in_srcImg,int width,int height);

    //保存分量文件
    static void saveChannelsToFiles(const QVector<QVector<unsigned char>> &in_imgs, int width, int height,const QString &format="rgb");

    //yuv420p转灰度 u/v设置成128
    static QVector<unsigned char> yuvToGray(const unsigned char *in_srcImg,int width,int height);
    //yuv420亮度减半
    static QVector<unsigned char> yuvToYhalf(const unsigned char *in_srcImg,int width,int height);

    //PSNR-质量评价
    //PSNR取值通常情况下都在20-50的范围内，取值越高，代表两张图像越接近，反映出受损图像质量越好。
    static int psnr(const unsigned char *in_srcImg,const unsigned char *in_delImg,int width,int height);
};

#endif // IMGHELPER_H
